﻿@section Styles{

        
      
    @*<link href="~/Content/css/dataTables.bootstrap.css" rel="stylesheet" />
    <link href="~/Content/css/bootstrap-table.css" rel="stylesheet" />
<link href="~/Scripts/plugins/layer/skin/layer.css" rel="stylesheet" />
<link href="~/Scripts/plugins/layer/skin/layer.ext.css" rel="stylesheet" />*@
}


<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">

                </div>
                <div class="ibox-content">
                    <div class="row" id="toolbar">
                        <div class="col-sm-2">
                            <a href="#" style="display:none" class="btn btn-primary pull-right md-trigger mrg-b-lg" data-modal="modal-13">
                                批量生成机器人
                            </a>
                            @*<button type="button" class="btn btn-w-m btn-primary" id="btnAdd">新增</button>*@
                        </div>
                        <div class="col-sm-2">
                        </div>
                        <div class="col-sm-2">
                            <select class="form-control" name="" id="state" style="width:110px;">
                                <option value="-1" selected>所有状态</option>
                                <option value="1">启用</option>
                                <option value="0">未启用</option>
                            </select>
                        </div>
                        <div class="col-sm-2">
                            <div class="input-group">
                                <span class="input-group-btn">
                                    <input type="text" placeholder="搜索账号" class="input-s form-control" id="keyword" name="keyword">
                                    <button type="button" class="btn btn-s btn-primary" id="search">搜索</button>
                                </span>
                            </div>
                        </div>
                        <div class="col-sm-2">
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>


<div class="row" style="opacity: 1;">
    <div class="col-lg-12">
        <div class="row">
            <div class="col-lg-12">
                <ol class="breadcrumb">
                    <li><a href="#">主页</a></li>
                    <li class="active"><span>系统设置</span></li>
                </ol>
                <div class="clearfix">
                    <h1 class="pull-left">机器人邀请码列表</h1>
                    <div class="pull-right top-page-ui">
                        <a href="#" class="btn btn-primary pull-right">
                            <i class="fa fa-plus-circle fa-lg"></i> 购买邀请码
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="main-box no-header clearfix">
                    <div class="main-box-body clearfix">
                        <div class="main-box-body table-responsive">
                            <table class="table table-hover" data-toggle="table" data-toolbar="#toolbar" id="acc_tb" data-pagination="true" >
                                <thead>
                                    <tr>
                                        <th data-field="activation" data-align="center">激活码</th>
                                        <th data-field="name" data-align="left">客户端名称</th>
                                        <th data-field="account" data-align="left" data-formatter="accountformatter">账号</th>
                                        <th data-field="state" data-align="center" data-sortable="true" data-formatter="stateformatter">状态</th>

                                        <th data-field="start_date" data-align="center" data-sortable="true" data-formatter="dateFormatter">开始时间</th>

                                        <th data-field="end_date" data-align="center" data-sortable="true" data-formatter="dateFormatter">到期时间</th>
                                        <th data-align="center" data-formatter="operateFormatter">操作</th>
                                    </tr>
                                </thead>

                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div class="md-modal md-effect-13" id="modal-13">
    <div class="md-content">
        <div class="modal-header">
            <button class="md-close close">&times;</button>
            <h4 class="modal-title">注册机器人</h4>
        </div>
        <div class="modal-body">
            <div class="main-box-body clearfix">
                <form class="form-horizontal">
                    <input type="hidden" id="id" name="id" value="0" />
                    <div class="form-group">
                        <label for="rname" class="col-lg-2 control-label">机器人账号:</label>
                        <div class="col-lg-5">
                            <input type="text" id="rname" name="rname" max="10" value="" class="form-control" placeholder="输入机器人账号">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="rpw1" class="col-lg-2 control-label">密码:</label>
                        <div class="col-lg-5">
                            <input type="password" id="rpw1" name="rpw1" max="10" value="" class="form-control" placeholder="输入密码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="rpw2" class="col-lg-2 control-label">确认密码:</label>
                        <div class="col-lg-5">
                            <input type="password" id="rpw2" name="rpw2" max="10" value="" class="form-control" placeholder="输入确认密码">
                        </div>
                    </div>
                    <div class="modal-footer">
                      
                         <button type="button" id="submit" class="btn btn-primary">保 &nbsp;&nbsp;&nbsp;存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="md-overlay"></div>
<input type="hidden" value="1" id="handle_status" />



@section Scripts{


    @*<script src="~/Scripts/plugins/bootstrap-table/bootstrap-table.min.js"></script>
        <script src="~/Scripts/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

        <script src="~/Scripts/plugins/layer/layer.min.js"></script>
        <script src="~/Scripts/sys/lib/common_raw.js"></script>

        <script src="~/js/modalEffects.js"></script>
        <script src="~/js/classie.js"></script>*@



    <script src="~/Scripts/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="~/Scripts/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>



    <script src="~/Scripts/plugins/layer/layer.min.js"></script>
    <script type="text/javascript" src="~/Scripts/sys/lib/common_raw.js"></script>


  @*<script src="/js/demo.js"></script>  
<script src="/js/modernizr.custom.js"></script>*@
    <script src="~/js/classie.js"></script>
<script src="~/js/modalEffects.js"></script>

@*<script src="~/js/pace.min.js"></script>*@

@*<script src="/js/demo-rtl.js" ></script>




<script src="/js/demo-skin-changer.js" ></script>

<script src="/js/bootstrap.js" ></script>
<script src="/js/jquery.nanoscroller.min.js" ></script>


<script src="/js/modernizr.custom.js"></script>

<script src="/js/scripts.js"  ></script>*@



    <script type="text/javascript">

        function initAcTable() {
            $('#acc_tb').bootstrapTable('destroy');
            common.initAcTable("acc_tb", "toolbar", "post", "/getrobots.html",
                function (data) {
                    if (!data.State) {
                        common.msg(data.Message, 1);
                    }
                },
                function (e) { },
                true, true, false, 10, 1, "[10,20,30,50]", { keyword: $("#keyword").val(), state: $("#state").val() });
        }

        $(document).ready(function () {

            initAcTable();

            $("#search").bind("click", function () {
                var load_index3 = layer.load(0, { shade: 0.6 });
                initAcTable();
                layer.close(load_index3);
            });

            $("#state").change(function () {
                var load_index2 = layer.load(0, { shade: 0.6 });
                initAcTable();
                layer.close(load_index2);
            });



            $("#btnAdd").click(function () {
                window.location.href = '/editRobot.html';
                //layer.open({
                //    type: 2,
                //    title: '新增机器人',
                //    shadeClose: false,
                //    shade: 0.8,
                //    area: ['70%', '50%'],
                //    content: '/editRobot.html'
                //});
            });
        });

        var parengPanel;

        function Edit(activation, name) {
            window.location.href = '/editRobot.html?activation=' + activation;
            //parengPanel = layer.open({
            //    type: 2,
            //    title: '编辑机器人【' + name + '】',
            //    shadeClose: false,
            //    shade: 0.8,
            //    area: ['70%', '50%'],
            //    content: '/editRobot.html?activation=' + activation
            //});
        }

        function stateformatter(data, row) {
            return row.state == 1 ? "<span name='state_" + row.id + "'>启用</span>" : "<span style='color:red;' name='state_" + row.id + "'></span>";
        }

        function operateFormatter(index, row) {

            var html = "";
            if (row.account == null || row.account == '') {
                //注册

                html = "<span onclick=\"Reg('" + row.activation + "')\" class=\"label label-danger md-trigger\" >注册</span>";
             //   html += '<a data-toggle="modal" href="#" class="btn btn-primary mrg-b-lg"  data-modal="modal-13">Standard Boostrap Modal</a>';
                // html+= '<button  onclick="Reg(' + row.activation + ')"  class="md-trigger btn btn-primary mrg-b-lg" data-modal="modal-13">Slide in (right)</button>';
              //  html = "<a data-toggle=\"modal\" href=\"#modal-13\" class=\"btn btn-primary mrg-b-lg\">注册</a>";
            }
            else {
                //编辑
                html = "<a  name='opera_" + row.activation + "' href=\"javascript:Edit('" + row.activation + "','" + row.name + "')\" class=\"table-link\"><span class=\"fa-stack\"><i class=\"fa fa-square fa-stack-2x\"></i><i class=\"fa fa-pencil fa-stack-1x fa-inverse\"></i></span></a>";

                //html = "<a name='opera_" + row.activation + "' href=\"javascript:Edit('" + row.activation + "','" + row.name + "')\"><i class=\"fa fa-edit text-navy\"></i>编辑</a>";

            }



            return html;
        }
        function accountformatter(index, row) {
            var html = "";
            if (row.account == null || row.account == '') {
                html = "<span class=\"label label-danger\">未注册</span>";
            }
            else
                html = row.account;
            return html;
        }


        //
        function Reg(id) {
            $("#id").val(id);
           
            $("#modal-13").addClass("md-show");
        }


        $(document).ready(function () {

            $("#submit").bind("click", function () {
                var name = $.trim($("#rname").val());
                if (name.length <5) {
                    layer.tips('请输入5位数以上账号！', '#rname', { tips: [2, '#78BA32'] });
                    return false;
                }
                var rpw1 = $('#rpw1').val();
                var rpw2 = $('#rpw2').val();
               
                if (rpw1.length == 0)
                {
                    layer.tips('密码不能为空！', '#rpw1', { tips: [2, '#78BA32'] });
                    return false;
                }
                if (rpw1 !=rpw2) {
                    layer.tips('两次密码不一样！', '#rpw2', { tips: [2, '#78BA32'] });
                    return false;
                }


                var id = $("#id").val();

                common.invokeApi(
                    "POST",
                    "/regRobot.html",
                    { rid: id, rpw1: rpw1, rpw2: rpw2, rname: name },
                    function () { },
                    function (data) {

                        alert(data.Message);
                        window.location.reload();
                        //common.msg(data.Message, 1, function () {
                        //$("#id").val("0");
                        //    $("#rname]").val("");
                        //    $(".md-close").trigger("click");

                            initAcTable();
                        //});
                    },
                    function (data) {
                        // common.msg(data.Message, 2, function () { });
                        alert(data.Message);
                    },
                    function () { }
                    );
            });

        });

    </script>
}